//
//  NSArray+ZZUtil.m
//  OCFrame
//
//  Created by hfzhangzhang on 2016/12/19.
//  Copyright © 2016年 hfzhangzhang. All rights reserved.
//

#import "NSArray+ZZUtil.h"
#import "DynamicTools.h"

@implementation NSArray (ZZUtil)

@end

@implementation NSArray (lifecycle)
+ (void)load {
    Class aClass = objc_getClass("__NSArrayI");
    SEL originalSel = @selector(objectAtIndexedSubscript:);
    SEL swizzledSel = @selector(dym_objectAtIndexedSubscript:);
    Swizzle_(aClass, originalSel, swizzledSel);
}

- (id)dym_objectAtIndexedSubscript:(NSUInteger)index {
    
    @try {
        return [self dym_objectAtIndexedSubscript:index];
    } @catch (NSException *exception) {
        NSLog(@"数组越界");
        return nil;
    }
}
@end


@implementation NSMutableArray (ZZUtil)

-(void)zz_addObjectWithProtectedMode:(id)anObject{
    if (anObject && ![anObject isKindOfClass:[NSNull class]]) {
        [self addObject:anObject];
    }
}
-(void)zz_addObjectsFromArrayWithProtectedMode:(NSArray*)othersArray{
    if (othersArray && ![othersArray isKindOfClass:[NSNull class]] && othersArray.count > 0) {
        [self addObjectsFromArray:othersArray];
    }
}
@end
